﻿using System;
using System.Linq.Expressions;

namespace FastTravel.Utilites
{
	public class Reflector
	{
		public static String GetPropertyName<T>(Expression<Func<T, object>> property)
		{
			UnaryExpression unaryExpression = property.Body as UnaryExpression;
			MemberExpression memberExpression =
				(MemberExpression)(unaryExpression != null ? unaryExpression.Operand : property.Body);
			return memberExpression.Member.Name;
		}

		public static String GetMethodName<T>(Expression<Func<T, object>> method)
		{
			MethodCallExpression methodCall = method.Body as MethodCallExpression;
			if (methodCall == null)
			{
				throw new ArgumentException();
			}
			return methodCall.Method.Name;
		}

	}
}
